package test;

import org.bhf.service.Service;
import org.bhf.service.ServiceMethod;

import java.util.Random;

@Service( name = "echo", crossSite = true )
public class EchoService
{
    Random r = new Random();

    @ServiceMethod
    public String   echo( final Echo that )
        throws Exception
    {
        if( that.delay > 0)
            Thread.sleep( that.delay );
        if( that.delay < 0)
            Thread.sleep( Math.abs( (int)(r.nextGaussian() * 200) ) );

        return that.value;
    }

    @ServiceMethod
    public void     echoException()
        throws Exception
    {
        throw new Exception( "ConversionError" );
    }

    @ServiceMethod
    public void     voidReturn( final Echo that )
        throws Exception
    {
    }

    @ServiceMethod
    public String   noArgs()
        throws Exception
    {
        return "hello";
    }

    public static class Echo
    {
        private String  value;
        private int     delay;

        public void setValue( String value )
        {
            this.value = value;
        }

        public void setDelay( int delay )
        {
            this.delay = delay;
        }

        public String getValue()
        {
            return value;
        }

        public int getDelay()
        {
            return delay;
        }
    }
}
